package com.skydonkey.validator;

import java.lang.reflect.Field;

public class CommonValidator {

    public static boolean hasEmptyStrings(Object o){
        return !nonEmptyStings(o);
    }

    public static boolean nonEmptyStings(Object o){
        try{
            Field[] fields = o.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                Object o1 = field.get(o);
                if (o1 instanceof String) {
                    String str = (String) o1;
                    if ("".equals(str)) {
                        return false;
                    }
                }
            }
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public static boolean hasEmptyFields(Object o){
        return !nonEmptyFields(o);
    }

    public static boolean nonEmptyFields(Object o){
        try{
            Field[] fields = o.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                Object o1 = field.get(o);
                if(o1 == null){
                    return false;
                }
            }
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
